Skip to content

feat: add client-grants command resource - #1598

Open
developerkunal wants to merge 7 commits into
feat/go-auth0-v3-migrationfrom
feat/client-grants-commands
Open

feat: add client-grants command resource#1598
developerkunal wants to merge 7 commits into
feat/go-auth0-v3-migrationfrom
feat/client-grants-commands

Conversation

@developerkunal

@developerkunal developerkunal commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🔧 Changes

Adds a client-grants command group so the CLI has full CRUD coverage for client grants, backed by the go-auth0 v3 Management SDK.

New commands:

  • auth0 client-grants list — list client grants, filterable by --client-id, --audience, --subject-type, --default-for, and --allow-any-organization.
  • auth0 client-grants create — authorize an application against an API, or create a default grant for a group of clients.
  • auth0 client-grants show — show a single client grant.
  • auth0 client-grants update — change a grant's scopes, organization settings, and authorization details types.
  • auth0 client-grants delete — remove a grant.

Create behavior:

  • A grant targets either a specific client (--client-id) or a default group (--default-for), which are mutually exclusive and exactly one is required. --default-for accepts third_party_clients, and interactively the target is chosen up front with the default-group values sourced from a list so new values become selectable without more code.
  • --authorization-details-types sets the authorization_details types allowed for the grant (Rich Authorization Requests). Interactively these are offered as a multi-select sourced from the audience API, skipping the prompt when the API defines none. It is available on both create and update.
  • Scopes can be set three ways, matching the API: specific scopes (--scopes), every scope on the API (--allow-all-scopes), or no scopes at all. An empty scope list is sent to the API as [] rather than being dropped.
  • --subject-type accepts client, user, or anonymous_user. The organization flags (--organization-usage, --allow-any-organization) are rejected for the user and anonymous_user subject types, and are not sent for a default grant, because the API does not allow organization settings in those cases.
  • Organization settings are not sent for a system API audience, which the API rejects with a reserved_identifier error, and allow_any_organization is only sent when the user actually sets an organization usage or the flag, so a grant that never touches organizations no longer carries a stray value.
  • The audience API is read once per command and shared between the scope and authorization-details pickers rather than read separately by each.

Display:

  • The detail view always shows the subject type, defaulting an empty value to client so it reads clearly, and shows the authorization details types when the grant has any, truncated to the terminal width like the scope list.

The v3 SDK client-grant wrapper replaces the v1 one, and the existing callers (quickstarts, terraform export, and the test command) are moved over to it.

📚 References

N/A

🔬 Testing

  • Added table-driven unit tests for the command input handling, the --default-for / --client-id mutual exclusivity, the authorization details types, the organization-settings guards, subject-type validation, and the display views.
  • Added commander integration tests (test/integration/client-grants-test-cases.yaml) covering list, create (specific / all / no scopes), show, update, delete, the --default-for paths, and the validation failure paths, plus helper scripts.
  • Manually exercised the full command surface against a live tenant, including empty-scope grants on both custom and system APIs, default grants, and the subject-type and organization validation paths.

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

Add a client-grants command group (list, create, show, update, delete)
backed by the go-auth0 v3 Management SDK, giving the CLI full CRUD
coverage for client grants.

Create supports specific scopes, all scopes (--allow-all-scopes), or no
scopes at all, matching the API. It also accepts --subject-type
(client, user, anonymous_user); the organization flags are rejected for
user and anonymous_user subject types, which the API does not allow.

The detail view always shows the subject type, defaulting an empty value
to client so it reads clearly. The v3 SDK client grant wrapper replaces
the v1 one, and the callers that used it (quickstarts, terraform, test)
are moved over.

Adds unit tests, commander integration tests and helper scripts, and the
generated command docs.
@developerkunal
developerkunal requested a review from a team as a code owner August 5, 2026 19:17
Temporary: allow the integration-tests job to run on PRs targeting
feat/go-auth0-v3-migration so the client-grants suite is exercised
against the live tenant. Revert before merge.
The detail view now always shows SUBJECT TYPE, which is the widest
label, so the label column pads wider than before. Update the expected
spacing in the show-table integration test to match.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.95080% with 180 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feat/go-auth0-v3-migration@190477d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
internal/cli/client_grants.go 70.17% 126 Missing and 27 partials ⚠️
internal/display/client_grant.go 86.25% 17 Missing and 1 partial ⚠️
internal/cli/test.go 50.00% 7 Missing ⚠️
internal/cli/terraform_fetcher.go 87.50% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@                      Coverage Diff                      @@
##             feat/go-auth0-v3-migration    #1598   +/-   ##
=============================================================
  Coverage                              ?   59.87%           
=============================================================
  Files                                 ?      124           
  Lines                                 ?    24176           
  Branches                              ?        0           
=============================================================
  Hits                                  ?    14475           
  Misses                                ?     8792           
  Partials                              ?      909           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Update and delete now fail fast when a client grant is a system grant
(is_system), which Auth0 refuses to modify, instead of surfacing the raw
400 after the whole interactive flow. System grants are also hidden from
the update and delete pickers so they can't be selected.

The update scope picker now offers the No scopes option too, matching
create. Choosing it sends scope: [] so the grant's scopes are cleared,
rather than being read as leaving them untouched.
Update now reads the grant's immutable subject type and, like create,
skips the organization prompts and request fields for the user and
anonymous_user subject types, which Auth0 rejects organization settings
on. It also runs the subject-type validation so the flag path fails fast
with a clear message.

Both create and update now drop the all-scopes option in the interactive
picker when the audience is a system API, since Auth0 rejects
allow_all_scopes on system APIs.
…opes

Add command-level tests for the update system-grant fail-fast, the update
subject-type organization guard, and the delete system-grant fail-fast.

Also document that a user subject-type grant against the Auth0 Management
API takes a fixed current_user scope set that cannot be listed dynamically,
so the scopes must be passed inline with --scopes.
Add --default-for (mutually exclusive with --client-id) and
--authorization-details-types to client-grants create, and
--authorization-details-types to update. Both are selectable
interactively, sourced from the audience API, and the audience API is
read once and shared between the scope and authorization-details pickers.

Skip organization settings for system APIs, which reject them with a
reserved_identifier error, and stop sending a stray allow_any_organization
when the user never engaged with organization settings. Show the
authorization details types in the detail view, truncated like scopes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants